package http;

public class Link {
	private String url;
	private String absoluteUrl = "";
	public Link (String url) {
		this.url = url;
	}
	public void setAbsoluteUrl(String absoluteUrl) {
		this.absoluteUrl = absoluteUrl;
	}
	public String toString() {
		String retVal = null;
		if (!url.contains("http://"))
			retVal = absoluteUrl+url;
		else retVal = url;
		while (retVal.contains("//"))
			retVal = retVal.replace("//", "/");
		
		retVal = retVal.replace("http:/", "http://");
		
		return retVal;
		/*Pattern absolute = Pattern.compile("^(https?://[^/]+/?).*$");
		Pattern relative = Pattern.compile("^[^/].*$");
		Pattern halfabsolute = Pattern.compile("^/.*$");
		Matcher absolutematcher = absolute.matcher(this.url);
		Matcher halfabsolutematcher = absolute.matcher(this.absoluteUrl);
		String url = null;
		if (absolutematcher.matches())
			url = this.url;
		if (relative.matcher(this.url).matches())
			url = this.absoluteUrl.concat(this.url);
		if (halfabsolutematcher.matches() && halfabsolute.matcher(this.url).matches())
			url = halfabsolutematcher.group(0).concat("/").concat(this.url);
		while (url.contains("//"))
			url = url.replace("//", "/");
		url = url.replace("http:/", "http://");*/
	}
}
